#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int minCut(string s) {
        int n = s.size();
        vector<vector<bool>> dp(n, vector<bool>(n));
        for (int i = n - 1; i >= 0; i--)
        {
            for (int j = i; j < n; j++)
            {
                if (s[i] != s[j]) dp[i][j] = false;
                else if (i == j || i + 1 == j) dp[i][j] = true;
                else if (dp[i + 1][j - 1]) dp[i][j] = true;
                else dp[i][j] = false;
            }
        }

        vector<int> p(n, 2000);
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j <= i; j++)
            {
                if (dp[j][i] && j == 0) p[i] = 0;
                else if (dp[j][i]) p[i] = min(p[i], p[j - 1] + 1);
                else p[i] = min(p[i], i);
            }
            cout << p[i] << ' ';
        }
        return p[n - 1];
    }
};